package com.study.contoller;

import com.study.R;
import com.study.entity.PatriarchRead;
import com.study.service.PatriarchReadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author:zt
 * @createDate: 2022/6/23
 */
@RestController
@RequestMapping("/api/patriarch-read")
public class PatriarchReadController {

    @Autowired
    private PatriarchReadService patriarchReadService;

    @PostMapping("upload")
    public R test5(MultipartFile aa)throws Exception{

        if(aa==null||aa.isEmpty()){
            return R.error().setMessage("请选择要上传的文件");
        }

//    InputStream in = aa.getInputStream();

        File file = new File("d:/upload/"+aa.getOriginalFilename());

        aa.transferTo(file);

        return R.map().put("文件名", aa.getOriginalFilename())
                .put("文件类型", aa.getContentType())
                .put("文件大小",aa.getSize());
    }

    @PostMapping("add")
    public R add(@RequestBody PatriarchRead pd) {
        return R.ok().setData(patriarchReadService.insertSelective(pd));
    }

    @GetMapping("list")
    public R page(
    ) {

        return R.ok().setData(patriarchReadService.selects());
    }


}
